<template>
  <div>
    <el-menu default-active="1-4-1" class="el-menu-vertical-demo" :collapse="myshow" @open="handleOpen" @close="handleClose">
      <nuxt-link class="wenzi" to="/frontsystem">
        <div class="logobox" style="margin-bottom: 20px;">
          <img class="logoimg" src="../assets/img/peony.png">
        </div>
      </nuxt-link>

      <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.name">
        <template slot="title">
          <svg-icon :icon-class="menu.icon" />
          <span>{{ menu.name }}</span>
        </template>
        <el-menu-item-group>
          <nuxt-link v-for="chmenu in menu.children" :key="chmenu.menuid" class="wenzi" :to="chmenu.path">
            <el-menu-item id="el-menu-item-id" :index="menu.sort + '-' + chmenu.sort">
              <svg-icon :icon-class="chmenu.icon" />
              <span>{{ chmenu.name }}</span>
            </el-menu-item>
          </nuxt-link>
        </el-menu-item-group>
      </el-submenu>
      <el-menu-item index="4" disabled>
        <i class="el-icon-document" />
        <span slot="title">导航三</span>
      </el-menu-item>
      <el-menu-item index="5">
        <i class="el-icon-setting" />
        <span slot="title">导航四</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<script>
import { listMenu } from '@/api/userMG'
export default {
  props: {
    myshow: Boolean
  },
  data () {
    return {
      allmenu: []
    }
  },
  /**
   * 创建完毕
   */
  created () {
    this.getdata(this.formInline)
  },
  methods: {
    // 获取菜单列表
    getdata (parameter) {
      this.loading = true
      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      listMenu(parameter)
        .then((res) => {
          this.loading = false
          if (res.code !== 0) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.allmenu = res.data
          }
        })
        // eslint-disable-next-line handle-callback-err
        .catch((err) => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    handleOpen (key, keyPath) {
      // eslint-disable-next-line no-console
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      // eslint-disable-next-line no-console
      console.log(key, keyPath)
    }
  }
}

</script>
<style lang="scss">
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 150px;
    min-height: 100%;
  }
  .el-menu--popup {
    min-width: 100px;
  }
  .wenzi {
    text-decoration:none;
  }
  .logobox {
    height: 40px;
    line-height: 40px;
    color: #9d9d9d;
    font-size: 20px;
    text-align: center;
    padding: 10px 0px;
  }
  .logoimg {
    height: 40px;
  }
</style>
